import React, { Component } from "react";
import PropType from "prop-types";

class TodoItem extends Component {
  handleClick = () => {
    const { onDelete, index } = this.props;
    if (onDelete) {
      onDelete(index);
    }
  };
  render() {
    const { item, test } = this.props;
    return (
      <div onClick={this.handleClick}>
        {test} - {item}
      </div>
    );
  }
}
// 定义数据类型
TodoItem.propTypes = {
  test: PropType.string.isRequired, // isRequired必传
  content: PropType.string,
  onDelete: PropType.func,
  index: PropType.number
};

// 默认值
TodoItem.defaultProps = {
  test: "hello  "
};

export default TodoItem;
